from pynput.mouse import Listener
import pyautogui
import pyperclip
import win32gui
import win32api
import win32con
import time
from PySide6.QtCore import QThread,Signal
import ctypes

# 全局变量
drag_flag = True
is_listening = False
PROCESS_PER_MONITOR_DPI_AWARE = 2
ctypes.windll.shcore.SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)
class BzListener(QThread):
    message_received = Signal(str)  # 定义一个信号，用于发送请求消息

    def run(self):
        with Listener(on_click=self.on_click) as listener:
            while is_listening:
                time.sleep(0.1)

    def on_click(self,x, y, button, pressed):
        global drag_flag, mouse_press, mouse_release
        if pressed:
            x, y = pyautogui.position()
            #print("按下", x, y)
            mouse_press = (x, y)
            drag_flag = False
        else:
            x, y = pyautogui.position()
            mouse_release = (x, y)
            #print("释放", mouse_release)
            drag_flag = True
            self.message_received.emit(str(x)+','+str(y))
        # if drag_flag:
        #     # 按下和释放的坐标不相等
        #     if mouse_press != mouse_release:
        #         print("这是鼠标拖动")
        #     else:
        #         print("这是鼠标点击")
        # else:
        #     pass

